package Ms

import (
	"database/sql"
	"fmt"
	"db2s/global"
	"runtime"
)

func (ms TableMeta) GetTablePartitionConfiguration(db *sql.DB, schema, table string) (tpc []global.TablePartitionConfig, err error) {
	var (
		event = "[GetTablePartitionConfiguration]"
		//execTimeout int64
		//f1          any
	)
	pc, _, _, _ := runtime.Caller(1)
	callingFunc := runtime.FuncForPC(pc)
	callFile, callLine := callingFunc.FileLine(pc)
	callFunc := callingFunc.Name()
	callFuncInfo := fmt.Sprintf("Call functions %v Call File %v:%v", callFunc, callFile, callLine)
	vlog = fmt.Sprintf("(%d) %v %v Start checking whether table %v.%v exists.", ms.LogThreadSeq, callFuncInfo, event, schema, table)
	WLog.Debug(vlog)
	return
	//strSql := fmt.Sprintf("SELECT A.OWNER AS \"schema\", A.TABLE_NAME AS \"table\",A.PARTITIONING_TYPE AS \"partitionType\", A.SUBPARTITIONING_TYPE AS \"subPartitionType\", B.PARTITION_NAME AS \"partitionName\",C.COLUMN_NAME as \"partitionColumnName\",C.DATA_TYPE AS \"partitionColumnType\",B.HIGH_VALUE AS \"partitionRules\", B.PARTITION_POSITION AS \"partitionSeq\",'single' as shardName,'-1' as \"partitionId\" FROM ALL_PART_TABLES A LEFT JOIN ALL_TAB_PARTITIONS B ON A.OWNER = B.TABLE_OWNER AND A.TABLE_NAME = B.TABLE_NAME JOIN ALL_TAB_COLUMNS C ON A.OWNER = C.OWNER AND A.TABLE_NAME = C.TABLE_NAME LEFT JOIN ALL_PART_KEY_COLUMNS D ON C.OWNER = D.OWNER AND C.TABLE_NAME = D.NAME AND C.COLUMN_NAME = D.COLUMN_NAME WHERE A.OWNER = '%v' AND A.TABLE_NAME = '%v' AND D.OBJECT_TYPE = 'TABLE' ORDER BY B.PARTITION_POSITION", schema, table)
	//dispos := dataDispos.DBdataDispos{DBType: DBType, DB: db, StopTime: or.SqlExecStopTime}
	//if execTimeout, f1, err = dispos.SqlQuery(strSql, "smap"); err != nil {
	//	vlog = fmt.Sprintf("(%d) %v %v The execution of a sql statement failed. sql is {%v},error is {%v}", or.LogThreadSeq, callFuncInfo, event, strSql, err)
	//	WLog.Warn(vlog)
	//	return nil, err
	//}
	//vlog = fmt.Sprintf("(%d) %v %v A sql statement was executed successfully. sql is {%v}, exec timeout is {%vms}", or.LogThreadSeq, callFuncInfo, event, strSql, execTimeout)
	//WLog.Debug(vlog)
	//if f1 != nil {
	//	f2 := f1.([]map[string]interface{})
	//	for _, v := range f2 {
	//		v1 := global.TablePartitionConfig{}
	//		// 将 map 转换为 JSON 字节流
	//		var jsonData []byte
	//		jsonData, err = json.Marshal(v)
	//		if err != nil {
	//			vlog = fmt.Sprintf("(%d) %v %s map[string]interfacle strconv json fail. map data is {%v} err info is {%v}", or.LogThreadSeq, callFuncInfo, event, v, err)
	//			WLog.Error(vlog)
	//			return
	//		}
	//		// 将 JSON 字节流反序列化为结构体
	//		err = json.Unmarshal(jsonData, &v1)
	//		if err != nil {
	//			vlog = fmt.Sprintf("(%d) %v %s json strconv struct fail. json data is {%v} err info is {%v}", or.LogThreadSeq, callFuncInfo, event, jsonData, err)
	//			WLog.Error(vlog)
	//			return
	//		}
	//		tpc = append(tpc, v1)
	//	}
	//}
	//return
}
